<template>
  <div class="container">
    <div class="customer">
      <div class="top flex">
        <div class="left">
          <span class="customer_pic">
            <img
              :src="guest_info.headurl !== '0' ? guest_info.headurl : '/static/imgs/system_user.png'"
            >
          </span>
        </div>
        <div class="right flex-item">
          <span class="customer_name">{{guest_info.name}}</span>
          <span class="customer_phone">手机号 {{guest_info.phone}}</span>
          <span class="customer_arrivetime">最近到店时间: {{guest_info.arrivetime}}</span>
        </div>
      </div>
      <div class="bottom">
        <div class="flex">
          <span class="flex-item">会员卡号</span>
          <span>{{guest_info.vipcard}}</span>
        </div>
        <div class="flex">
          <span class="flex-item">会员卡等级</span>
          <span>{{guest_info.vipname}}</span>
        </div>
        <div class="flex">
          <span class="flex-item">现金余额</span>
          <span>{{guest_info.balance}}元</span>
        </div>
        <div class="flex">
          <span class="flex-item">赠送余额</span>
          <span>{{guest_info.giftbalance}}元</span>
        </div>
        <div class="flex">
          <span class="flex-item">积分余额</span>
          <span>{{guest_info.score}}积分</span>
        </div>
      </div>
    </div>
    <div class="accountinfo">
      <div class="title">
        <i class="shu"></i>
        <span>次卡账户信息</span>
      </div>
      <div class="body">
        <ul v-if="cika_list.length != 0">
          <div v-for="(item,index) in cika_list" :key="index">
            <div class="flex">
              <span class="flex-item layout">{{item.name}}</span>
              <span>{{item.nownum}}/{{item.num}}</span>
            </div>
            <div class="flex">
              <span class="flex-item flexstart">
                <i class="shopicon"></i>
                {{item.shopname}}
              </span>
              <span>
                所属:
                <i v-if="item.cardname == 0" class="inline">次卡</i>
                <i v-else class="inline">{{item.cardname}}</i>
              </span>
            </div>
          </div>
        </ul>
        <ul v-else class="none">
          <span>没有客户次卡信息</span>
        </ul>
      </div>
    </div>
    <div class="accountinfo">
      <div class="title">
        <i class="shu"></i>
        <span>期卡账户信息</span>
      </div>
      <div class="body">
        <ul v-if="qika_list.length != 0">
          <div v-for="(item,index) in qika_list" :key="index">
            <div class="flex">
              <span class="flex-item layout">{{item.name}}</span>
              <span>到期: {{item.endtime}}</span>
            </div>
            <div class="flex">
              <span class="flex-item flexstart">
                <i class="shopicon"></i>
                {{item.shopname}}
              </span>
              <span>
                所属:
                <i v-if="item.cardname == 0" class="inline">次卡</i>
                <i v-else class="inline">{{item.cardname}}</i>
              </span>
            </div>
          </div>
        </ul>
        <ul v-else class="none">
          <span>没有客户期卡信息</span>
        </ul>
      </div>
    </div>
    <div class="accountinfo">
      <div class="title">
        <i class="shu"></i>
        <span>暂存账户信息</span>
      </div>
      <div class="body">
        <ul v-if="goods_list.length != 0">
          <div v-for="(item,index) in goods_list" :key="index">
            <div class="flex">
              <span class="flex-item layout">{{item.goodsname}}</span>
              <span>{{item.nownum}}/{{item.num}}</span>
            </div>
            <div class="flex">
              <span class="flex-item flexstart">
                <i class="shopicon"></i>
                {{item.shopname}}
              </span>
              <span>暂存时间: {{item.addtime}}</span>
            </div>
          </div>
        </ul>
        <ul v-else class="none">
          <span>没有客户暂存信息</span>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import moment from 'moment'
import api from '@/utils/api'
import Toast from '@/utils/toast'
export default {
  data () {
    return {
      guest_id: '',
      guest_info: {},
      cika_list: [],
      qika_list: [],
      goods_list: []
    }
  },
  components: {
  },
  async onLoad () {
    const that = this
    // 接收客户id
    that.guest_id = that.$route.query.id
    // 请求数据
    await Promise.all([
      that.get_info(),
      that.get_cika(),
      that.get_qika(),
      that.get_goods()
    ])
  },
  methods: {
    async get_info () {
      const that = this
      const res = await api.getguestaccountinfo({
        guest_id: that.guest_id
      })
      if (res.code === '100') {
        res.data[0]['balance'] = res.data[0]['balance'].toFixed(2)
        res.data[0]['giftbalance'] = res.data[0]['giftbalance'].toFixed(2)
        res.data[0]['arrivetime'] = moment.unix(res.data[0].arrivetime).format('YYYY-MM-DD HH:mm')
        if (res.data[0]['vipname'] === null) {
          res.data[0]['vipname'] = '非会员'
        }
        that.guest_info = res.data[0]
      } else {
        Toast(res.msg, 'noicon')
      }
    },
    async get_cika () {
      const that = this
      const res = await api.getguestcikalist({
        guest_id: that.guest_id
      })
      if (res.code === '100') {
        that.cika_list = res.data
      } else {
        that.cika_list = []
        Toast(res.msg, 'noicon')
      }
    },
    async get_qika () {
      const that = this
      const res = await api.getguestqikalist({
        guest_id: that.guest_id
      })
      if (res.code === '100') {
        res.data.forEach(ele => {
          ele.endtime = moment.unix(ele.endtime).format('YYYY-MM-DD')
        })
        that.qika_list = res.data
      } else {
        that.qika_list = []
        Toast(res.msg, 'noicon')
      }
    },
    async get_goods () {
      const that = this
      const res = await api.getguestgoodslist({
        guest_id: that.guest_id
      })
      console.log(res)
      if (res.code === '100') {
        res.data.forEach(ele => {
          ele.addtime = moment.unix(ele.addtime).format('YYYY-MM-DD')
        })
        that.goods_list = res.data
      } else {
        that.goods_list = []
        Toast(res.msg, 'noicon')
      }
    }
  }
}
</script>

<style scoped>
.customer {
  width: 100%;
  padding-left: 32rpx;
  background-color: rgba(255, 255, 255, 1);
}
.customer .top {
  height: 192rpx;
}
.customer .top .left {
  margin-right: 40rpx;
}
.customer_pic,
.customer_pic img {
  width: 120rpx;
  height: 120rpx;
  border-radius: 50%;
}
.customer .top .right span {
  display: block;
  font-size: 28rpx;
  color: rgba(102, 102, 102, 1);
}
.customer_name {
  font-size: 32rpx !important;
  font-weight: bold;
  color: rgba(51, 51, 51, 1);
}
.customer .bottom div {
  height: 80rpx;
  border-bottom: 2rpx solid rgba(153, 153, 153, 0.1);
  font-size: 32rpx;
  color: rgba(51, 51, 51, 1);
}
.customer .bottom div:last-child {
  border-bottom: none;
}
.customer .bottom div span:last-child {
  padding-right: 26rpx;
  color: rgba(102, 102, 102, 1);
}
.accountinfo {
  width: 100%;
  padding-left: 32rpx;
  font-size: 32rpx;
  color: rgba(102, 102, 102, 1);
  margin-top: 22rpx;
  background-color: #fff;
}
.accountinfo .title {
  padding-top: 22rpx;
  font-weight: bold;
}
.accountinfo .body ul > div {
  padding-bottom: 22rpx;
  border-bottom: 2rpx solid rgba(153, 153, 153, 0.1);
  font-size: 26rpx;
  color: rgba(102, 102, 102, 1);
}
.accountinfo .body ul > div > div {
  padding-right: 28rpx;
}
.shu {
  display: inline-block;
  width: 4rpx;
  height: 20rpx;
  background: rgba(255, 68, 68, 1);
  border-radius: 2rpx;
  margin-right: 12rpx;
}
.layout {
  padding: 22rpx 0;
  font-size: 28rpx;
  color: rgba(51, 51, 51, 1);
}
.shopicon {
  width: 24rpx;
  height: 20rpx;
  margin-right: 8rpx;
  background: url(http://mytimg.178mr.com/minishop.png) no-repeat;
  background-size: 100%;
}
.flexstart {
  display: flex;
  align-items: center;
}
.inline {
  display: inline-block;
}
.none {
  text-align: center;
  color: rgba(53, 53, 53, 1);
}
</style>